package com.eben.GUI;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;

import com.eben.R;

public class MainMenuActivity extends Activity {
	private Button startButton,highScoreButton,aboutButton,exitButton;
	
	private OnTouchListener touchListener = new OnTouchListener() {

		public boolean onTouch(View v, MotionEvent e) {
			//Toast.makeText(getApplicationContext(), v.getId() + "", Toast.LENGTH_SHORT).show();
			if(v.getId() == startButton.getId()){
				startButton.setBackgroundResource(R.drawable.play_ontouch);
				if(e.getAction() == 1){
                	startButton.setBackgroundResource(R.drawable.play);
                	Intent myIntent = new Intent(v.getContext(), GameActivity.class);
                    startActivityForResult(myIntent, 0);
                }
        	}else if(v.getId() == highScoreButton.getId()){
        		highScoreButton.setBackgroundResource(R.drawable.score_ontouch);
        		if(e.getAction() == 1){
        			highScoreButton.setBackgroundResource(R.drawable.score);
	        		Intent myIntent = new Intent(v.getContext(), HighScoreActivity.class);
	                startActivityForResult(myIntent, 0);
        		}
        	}else if(v.getId() == aboutButton.getId()){
        		aboutButton.setBackgroundResource(R.drawable.about_ontouch);
        		if(e.getAction() == 1){
	        		aboutButton.setBackgroundResource(R.drawable.about);
        			Intent myIntent = new Intent(v.getContext(), AboutActivity.class);
	                startActivityForResult(myIntent, 0);
        		}
        	}else if(v.getId() == exitButton.getId()){
        		exitButton.setBackgroundResource(R.drawable.exit_ontouch);
        		if(e.getAction() == 1){
        			exitButton.setBackgroundResource(R.drawable.exit);
        			System.exit(0);
        		}
        	}
			return false;
		}
	};
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        startButton = (Button)this.findViewById(R.id.start);
        highScoreButton = (Button)this.findViewById(R.id.highscore);
        aboutButton = (Button)this.findViewById(R.id.about);
        exitButton = (Button)this.findViewById(R.id.exit);
        
        startButton.setOnTouchListener(touchListener);
        highScoreButton.setOnTouchListener(touchListener);
        aboutButton.setOnTouchListener(touchListener);
        exitButton.setOnTouchListener(touchListener);
    }
    
    //Exits the application if you press escape in main menu instead of just closing activity.
    @Override
    public void onDestroy(){
    	super.onDestroy();
    	System.exit(0);
    }
    
//    @Override // code used to try the highscorelists
//    public void onResume(){
//    	double d = Math.random() * 1000;
//    	Preferences.setHighScore(new Highscore(new Score(d), "Jake" + (int)(d + 0.5)), this);
//    	super.onResume();
//    }
}
